package org.wu.framework.authorization.platform.infrastructure.persistence;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.wu.framework.authorization.platform.infrastructure.converter.SysDictionaryDataConverter;
import org.wu.framework.authorization.platform.infrastructure.entity.SysDictionaryDataDO;
import org.wu.framework.authorization.platform.domain.model.sys.dictionary.data.SysDictionaryData;
import org.wu.framework.authorization.platform.domain.model.sys.dictionary.data.SysDictionaryDataRepository;
import org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyInfrastructurePersistence;
import org.wu.framework.lazy.orm.database.lambda.stream.lambda.LazyLambdaStream;
import org.wu.framework.lazy.orm.database.lambda.stream.wrapper.LazyWrappers;
import org.wu.framework.lazy.orm.web.plus.AbstractLazyCrudRepository;
import org.wu.framework.web.response.Result;
import org.wu.framework.web.response.ResultFactory;

import java.util.List;

/**
 * describe
 *
 * @author Jia wei Wu
 * @date 2023/05/17 11:19 晚上
 * @see DefaultDDDLazyInfrastructurePersistence
 **/
@Repository
public class SysDictionaryDataRepositoryImpl extends
        AbstractLazyCrudRepository<SysDictionaryDataDO, SysDictionaryData, Integer> implements SysDictionaryDataRepository {

    @Autowired
    LazyLambdaStream lazyLambdaStream;


    /**
     * describe 新增
     *
     * @param
     * @return
     * @exception/throws
     * @author Jia wei Wu
     * @date 2023/05/17 11:19 晚上
     **/

    @Override
    public Result<SysDictionaryData> story(SysDictionaryData sysDictionaryData) {
        SysDictionaryDataDO sysDictionaryDataDO = SysDictionaryDataConverter.fromDictionaryData(sysDictionaryData);
        lazyLambdaStream.upsert(sysDictionaryDataDO);
        return ResultFactory.successOf();
    }

    /**
     * describe 查询单个
     *
     * @param
     * @return
     * @exception/throws
     * @author Jia wei Wu
     * @date 2023/05/17 11:19 晚上
     **/

    @Override
    public Result<SysDictionaryData> findOne(SysDictionaryData sysDictionaryData) {
        SysDictionaryDataDO sysDictionaryDataDO = SysDictionaryDataConverter.fromDictionaryData(sysDictionaryData);
        SysDictionaryData sysDictionaryDataOne = lazyLambdaStream.selectOne(LazyWrappers.lambdaWrapperBean(sysDictionaryDataDO), SysDictionaryData.class);
        return ResultFactory.successOf(sysDictionaryDataOne);
    }

    /**
     * describe 查询多个
     *
     * @param
     * @return
     * @exception/throws
     * @author Jia wei Wu
     * @date 2023/05/17 11:19 晚上
     **/

    @Override
    public Result<List<SysDictionaryData>> findList(SysDictionaryData sysDictionaryData) {
        SysDictionaryDataDO sysDictionaryDataDO = SysDictionaryDataConverter.fromDictionaryData(sysDictionaryData);
        List<SysDictionaryData> sysDictionaryDataList = lazyLambdaStream.selectList(LazyWrappers.lambdaWrapperBean(sysDictionaryDataDO), SysDictionaryData.class);
        return ResultFactory.successOf(sysDictionaryDataList);
    }

    /**
     * describe 根据字典编码获取字典数据
     *
     * @param dictionaryCodeList 字典编码
     * @return
     * @exception/throws
     * @author Jia wei Wu
     * @date 2023/05/17 11:19 晚上
     **/
    @Override
    public Result<List<SysDictionaryData>> findListByDictionaryCode(List<String> dictionaryCodeList) {
        List<SysDictionaryData> sysDictionaryDataList = lazyLambdaStream.selectList(LazyWrappers.<SysDictionaryDataDO>lambdaWrapper().in(SysDictionaryDataDO::getDictionaryCode,dictionaryCodeList), SysDictionaryData.class);
        return ResultFactory.successOf(sysDictionaryDataList);
    }

    /**
     * describe 删除
     *
     * @param
     * @return
     * @exception/throws
     * @author Jia wei Wu
     * @date 2023/05/17 11:19 晚上
     **/

    @Override
    public Result<SysDictionaryData> delete(SysDictionaryData sysDictionaryData) {
        SysDictionaryDataDO sysDictionaryDataDO = SysDictionaryDataConverter.fromDictionaryData(sysDictionaryData);
        //  lazyLambdaStream.remove(sysDictionaryDataDO);
        return ResultFactory.successOf();
    }

}